fixes to stream handling