fixed bug for computing weights.