Extracting ringbuffer logic into a separate library to simplify both