added comments and docstrings