Added the NewStateMachine that uses a stack for the transitions.