fix bug with end idx of last row.  Really need more unit tests