Ring buffer implementation