if statement logic wrong?