Refactored hash method