added comments to explain code