Added more comments and docstrings