Create state machine