Reducing complexity of if statement