Replace the inline loop with a call to the existing primaryParentView() helper so the selection algorithm lives in exactly one place.