I received some review notes from @chewxy
the algorithm looks correct
I think there may be plenty of efficiency to be gained by hoising Vocabulary out of the loop process
basically, have one pass to make Vacabulary first
but what you have here? absolutely should work