added undo and redo  functionality