numerous memory leaks fixed