Fixed bug in stats function