Various bits of stream-related refactoring.