Added comments to code for better understanding