some valgrind errors fixed