Fixing templating system to match a hierarchical state machine