Implement undo functionality