fix another problem with end row calculation
handle missing start and end rows better
more precise calculation of missing start and end rows