Fixed a few things Valgrind complains about, i.e memory leaks.

Fixed a few memory leaks and other things Valgrind complains about (uninitialized variables and such).