added explanatory comments to code