moved StateMachine constructor logic to StateMachine.create