fixed order of if statement