corrections with valgrind + tests