Counting word frequency in a string