fixing if statement logic