Extracted words counting logic into separate function.