Bug fix identified by valgrind