Reduce method complexity

Factor out some helper methods.

[#51559097]
Merge 51559097- to master

[#51559097]