Some memory leak fixes