several memory leaks fixed