Fixes #32; refactor unittests