This is the originally planned state diagram. The final code is writen with this state diagram as a base: State diagram highres image