CRM-20858: Fix Merging of Unselected Custom Fields and Refactor Code
When a Custom Group had more than one custom field and only some of those
fields were selected to be merged, all the fields in the custom group were
merged. This happened exclusively on contacts that had no record on the
custom group's table.
Fixed this by inserting a record on the custom group table before updating
references from source contact to target contact, this way, all values in the
custom group will start empty and only submitted values will get assigned.
Also refactored the solution to make it easier to read and used more descriptive
variable and function names.