cleaning up code and adding docstrings