Fixed add_data() to check for duplicates and update records whose ids are provided