fixed memory leaks (valgrind)