Improving FSMs: hierarchical finite-state machines