Refactor code

Reduce cyclomatic complexity by unifying pre and post 1.8 code paths.

[#51559097]
Merge 51559097- to master

[Completes #51559097]