optimizing an if statement