refactored stats.rb