reduce nesting by inverting an if