This is a partial of https://github.com/civicrm/civicrm-core/pull/16768 & consists of the lines I have reviewed from it