refactor ringbuffer