working on issue #8, and a few valgrind complaints