completed the word count function