if statement logic fix