Changed totaling to a foreach