contd cleaning, creating the state machine