dynamic hierarchical state machine