Moved the undo logic into it's own function and set Ctrl+Z to call it