Docstrings and refactoring