Implemented provenance functionality for gather_targets and gather_templates code