Added circular buffer for undo/redo