improve hash function based on #2027; close #2027