Start on major HSMF refactoring. Should compile, but not quite all tests pass as a little bit of work is left