bug fixed and valgrind check