making some memory leak fixes