fixed if statement order