Fixed some valgrind issues