added stream handling