Added comments to explain the functions