Enhancing undo functionality to handle shapes.