Refactored count_words using inject