Added a bunch of comments to the code