improved stream error handling in corner cases