this function still looks like it's doing way too much work. It's doing all kinds of position-rewriting, which should be the stream's job.