added comments to all the subfunctions