Fix fsm's bugs
Fix a termination bug