Fix several FSM bugs