docstrings and some code cleanup