corrected function for calculating hash key