implement for ringbuf, and add lots of comments
fix tests