Fixing FSM race conditions