setting up state machine