more fixes thanks to valgrind