tighter formatting
made more efficient by precomputing word counts for each class