Fixed calculation of hash