refactored java script. can switch now between totals and stats view