Added onEnter and onLeave funcs to state machine