Refactor nested if
Merge pull request #17784 from bruno-/refactor-nested-ifs

Refactor nested if