Fix very subtle bugs in output dequeuing

I think making one of these lets me comment on the code inline.