improved RingBuffer

improved RingBuffer and some bug fixed.