Better weighting algorithm