Wrong understanding towards circular buffer, wrong algorithm used, need to rework