Fixed problem found with valgrind