Expanded docstrings; refactored code.