refactored hash functions to make it much faster