Refactored StateMachine a bunch, simplifying things.