added comments and edited docstrings