invert if to reduce nesting

pure refactoring
invert if to reduce nesting

pure refactoring
invert if to reduce nesting

pure refactoring
invert if to reduce nesting

pure refactoring
minor formatting

whitespace cleanup