Corrected logic related to last row.