Refactor PHF generation