Added proper memory deallocation to hashmap

Also fixed other pieces of hash table to make it more durable.