Calculates sums