Make sure to ignore trailing empty rows in all places.

Otherwise it'd throw an exception.

All unit tests pass now.

Change-Id: I1dc49afcdf3e6604de4c0bc2440106c5ce0da090