WIP.  Code cleanup and documentation.