test cases working, valgrind errors