added comments to show how program works