working ringbuffer, not thread safe