Refactor complex method

[#57311364]