invert if to reduce nesting