added weighting loop