fix zero-row bug using if statements