CRM-14208, CRM-14140 use more of jsproffitt patch to simplify logic