Fix segfault after undo