Back out previous commit to some extent and fix by replacing $stats with $this->stats