calculating exact end of the stream