- refactored stream handling