Factored out CircularBuffer.