Refactoring and improving docstrings