Various minor changes and optimizations.
Update docstrings and comments.  Clean up some code.