Final code cleanup and docstrings