General additions to the memory leak issue
Patched major memory leaks revealed by valgrind