correctly calculate hash