refactor count_words