  Possible solution: Need to calculate total in advance, not in for