state machine working