Reimplemented a more lightweight internal circular buffer