implemented circular buffer for images