added a bunch of comments to describe the goings ons