Some fixes after running with valgrind