Finished and refactored preliminary threadsafe ringbuffer