Added a lot of comments and docstrings