added logic to update existing records