Please add a comment what is done in this loop, was not immediately obvious to me.
If I got it correctly, this makes sure that the paragraph (and any containing paragraphs, hm, in what structures would that happen?) in which the range starts is included in the result, right?