refactoring to move RingBuffer out of decoder (broken)