Clean up and document more code.

Addresses #24 and #32.