add docstrings, refactoring