Adding comments to explain how script works