Move mergeNestedReapeatedShadow and clean up a bit.