Modified code to do string check after hash check to prevent collisions.