Add docstrings, very minor refactoring.