Fix a bug
Improve function to make stats