Fix stream handling