use a lockfree ringbuffer instead of a queue to handle the output chunks

+ some optimizations