refactoring nesting if as cond