fixing state machine