Fix comments, clean up some debug spew, add a couple unit tests.