Silence valgrind by fixing a few bugs