Added undo and redo functionality