Optimize slow hash

credit to NoodleDoodleNoodleDoodleNoodleDoodleNoo