docstrings and refactoring