Fixed some memory leaks and made valgrind happy in regards to uninitialised variables.