Fleshing out the undo function