Refactoring hash-tree code