 	WHERE cs.valid_end_date = TO_DATE ('20991231', 'YYYYMMDD')
 	AND cs.invalid_reason IS NOT NULL;
 
-	--4. Fix valid_start_date for incorrect concepts (bad data in sources)
-	UPDATE concept_stage cs
-	SET valid_start_date = cs.valid_end_date - 1
-	WHERE cs.valid_end_date < cs.valid_start_date;
-
-	--5. Update concept_id in concept_stage from concept for existing concepts
+	--4. Update concept_id in concept_stage from concept for existing concepts
 	UPDATE concept_stage cs
 		SET concept_id = c.concept_id
 	FROM concept c
 	WHERE cs.concept_code = c.concept_code
 		AND cs.vocabulary_id = c.vocabulary_id;
 
-	--6. Analysing
+	--5. Analysing
 	ANALYSE concept_stage;
 	ANALYSE concept_relationship_stage;
 
-	--7. Clearing the concept_name
+	--6. Clearing the concept_name
 	--Remove double spaces, carriage return, newline, vertical tab and form feed
 	UPDATE concept_stage
 	SET concept_name = REGEXP_REPLACE(concept_name, '[[:cntrl:]]+', ' ', 'g')

	END = 1
	AND c.vocabulary_id NOT IN ('CPT4', 'HCPCS', 'ICD9Proc', 'ICD10PCS');

	--10.2. Update the concept for CPT4, ICD9Proc, HCPCS and ICD10PCS
	UPDATE concept c SET
		valid_end_date = (SELECT latest_update-1 FROM vocabulary WHERE vocabulary_id = c.vocabulary_id)
	WHERE NOT EXISTS (SELECT 1 FROM concept_stage cs WHERE cs.concept_id = c.concept_id AND cs.vocabulary_id = c.vocabulary_id) -- if concept missing from concept_stage

		AND c.valid_start_date <> cs.valid_start_date
		AND cs.valid_start_date <> v.latest_update; -- if we have a real date in concept_stage, use it. If it is only the release date, use the existing

	--8.6. For 'valid_end_date'
	UPDATE concept c
	SET valid_end_date = cs.valid_end_date
	FROM concept_stage cs
	WHERE c.concept_id = cs.concept_id
		AND c.valid_end_date <> cs.valid_end_date;

	--8.7. For 'invalid_reason'
	UPDATE concept c
	SET invalid_reason = cs.invalid_reason
	FROM concept_stage cs
	WHERE c.concept_id = cs.concept_id
		AND COALESCE(c.invalid_reason, 'X') <> COALESCE(cs.invalid_reason, 'X');

	--9. Deprecate concepts missing from concept_stage and are not already deprecated.
	--This only works for vocabularies where we expect a full set of active concepts in concept_stage.
	--If the vocabulary only provides changed concepts, this should not be run, and the update information is already dealt with in step 1.
	--20180523: new rule for CPT4, ICD9Proc and HCPCS: http://forums.ohdsi.org/t/proposal-to-keep-outdated-standard-concepts-active-and-standard/3695/22 and AVOF-981
	--20200730 added ICD10PCS
	--9.1. Update the concept for non-CPT4, non-ICD9Proc, non-HCPCS and non-ICD10PCS vocabularies
	UPDATE concept c SET
		invalid_reason = 'D',
		standard_concept = NULL,
