Reduce duplication and split complex method

[Fixes #62961826]

Signed-off-by: Abhijit Hiremagalur <abhi@pivotallabs.com>