added some undo logic