Improved stream handling