Ported stats rewrite from 4.8