Improve merging of group contents.

Fixes #474.

When concating/merging two groups, we now avoid unnecessary duplication
of fields. Also added a unit test.