helgrind and valgrind fixes