Fixed buggy hash calculations, some memory leaks fixed