Improve hash function to fix collision problem