Update stats.php

- fixed some bugs
- added new features