Added explanatory comments to code