refactored word count and distance for pmi