Fix a bunch of bugs in the stats refactor