Code refactors related to issue #42, and misc cleanup