clean up code, add docstrings