Added a lot of comments to the code