Improved the function for generating the hash of an object