modified program to only update fields that have changed