Tweaked the matchFamilies function so that it is more robust.