state machine work