Refactor complex method

[#54205148]
Merge 54205148-reduce-method-complexity to master

[#54205148]