Calculating total in other function