Rewrote parts of the streaming logic to be neater and generally better.