enhance eroor handling in StateMachine