Fixed a lot of code and mistype errors;
Now the memory is freed after replacing value in the hash.