Memory leaks reported by Valgrind fixed, more comments added