Rewrite to one generic count words function for both demand and products.