Set up state machine