Extract a few methods from stats calculation.

I think all of these methods could be better defined somewhere else, but
this is step 1.