Invert if statements

This reduces nesting.