better stream handling