fix memory problem -- thanks valgrind