Changed hash function and fixed a memory leak