adding circular buffer code