Add documentation and some cleanup.