Add documentation.

... and re-factor logging slightly.