Improved stats function.