added docstrings, code formatting improvements