optmize comp_het loop to avoid n^2