fixed a few bugs in StateMachine