Added comments to majority of the code