Corrected valgrind errors