Consolidated code

Undo button and popup menu use same code for undo action