Swapped order of conditions in if statement