added comments to explain the code