Move a few imports around, and add some docstrings.