Added a few more comments to explain the code better