fix code to surpress valgrind