Correcting the calculations for line index at end of buffers.