added lots of comments to the code