Improve the stats function. See #153