defining the state machine