Refactor h generation across the program to consolidate helper functions