fixed some of the memory leaks