cleaning the code for circular buffer use