invert if to reduce nesting

pure refactoring, shouldn't break anything