Completed the word count function