Use accumulate instead of for loop and summation