You’re adding the amount(s) to the previous total, rather than replacing it. Try
var tot = 0;
instead.