added docstrings and formatting