fixed leaks with valgrind, renamed functions