Added several comments to explain code