fixes segmentation fault error on repeatedly clicking undo