invert logic to have less nesting