fixed some memory leaks