CRM-14197 code refactor

as part of CRM-14197 I've done quite a bit of code refactor - am trying to break it into 'stand-alone' chunks to make eyeballable-PRs