Adding a undo and redo functionality