Refactor HFSM class hierarchy