change undo redo change to function instead of global variables