Adding totalWeight function