Fixes totalWeight function.