Some improvements suggested by valgrind