Refactored count_words dictionary creation