Many memory leaks fixed