some memory leak fixes