Cleanup, added docstrings, comments.