Better implementation of allSums.