Housekeeping. Clean up comments and refactor a bit.

In preparation for merge into master.