Cleaning up at the end to eliminate memory leaks detected by valgrind.