some memory leaks fixes