Rewritten pivot module to use underscore grouping and summing.