Beginnings of fix for Issue # 20 and misc cleanup.

This PR implements the beginnings of a fix for Issue # 20.

I made small commits to ease code review.  Feel free to [rebase and squash](http://rebaseandsqua.sh/) as you see fit.