refactor hash construction logic