Reformat code, add documentation

* Reformat the code to lines of 96 characters or less.  This makes it
  easier to read the source on github (and in editors that don't wrap
  lines).
* Add some documentation and start to make the format of the existing
  documentation more consistent.
* Do some minor cleanups of the code.