HPCC-9065 Restructure code while investigating optimization

Signed-off-by: Gavin Halliday <gavin.halliday@lexisnexis.com>
Merge pull request #5559 from ghalliday/issue9065

HPCC-9065 Restructure code while investigating optimization

Reviewed-By: Jamie Noss <james.noss@lexisnexis.com>
Reviewed-By: Richard Chapman <rchapman@hpccsystems.com>