Fixed some valgrind errors