implemented algorithm for recursively summing