fixed the valgrind errors