invert if to improve readability and reduce nesting