Heirarchical state machines