Refactor magic hashing