Improve cohort recognition code