Exit parent states failing. 

Fixed loop on change state. The counter (p) was never incremented, thus the loop would fail when exiting from a child state with a parent to a different state. 

Wasn't sure of how to run unit tests successfully. But to my mind this should be a valid test case.