misc improvements and clean-up; add basic unit-test