Refactor wordcount