Added docstrings, and made some other minor changes.