Exiting child state doesn't properly exit parents when moving to another state, as loop counter p is never incremented and loop doesn't exit properly.
Merge pull request #1 from thefuntastic/master

Exit parent states failing.