Modify the logic for calculating the last weight