fixed if statement logic