works, but needs valgrind