fix stream handling