Improved performance from 44.888 seconds -> 33.189 seconds. Bottleneck is the last few sums