added many comments to the code