Some memory leaks fixed