Got the state machine working