refactored calcHash