fixed the majority of memory leaks