working program, failing valgrind