More nuanced approach to merging arrays.

From #6769.