Improve _sum and _stats JS equivalents