Fixed a problem with end-of-stream handling.