refined if statement to make code more efficient