fix issues found via valgrind