Improved hashing function.