Ring buffer bug fixes