Ran valgrind leak-check and fixed memory leaks.