fix state machine