new circular buffer logic taht actually works, and is faster