Improved getHash function