fix some bad codes
fix bug in stats calc