full solution to word frequency