Refactor text_stats.