added comments to help understand the code