DO NOT MERGE: Work in progress, refactoring how statistics are calculated

This is a request for review.

@jglick @kohsuke any thoughts?