memory leak fixes