Fixed valgrind issues