fix if statement logic