Unoptimized undo function implemented.