minor code refactoring for word-count js