Added logic that the children pattern should carry its parent's shared nodes too.