Fixed state machine bugs