Refactored StateMachine, and added support for exit actions
Added documentation for StateMachine