Simplify logic to find best matches. Also, DRY.

Instead of storing a mapping of candidate function names to individual
scores, store a mapping of scores to an array of candidate function names.
Then, choose the one with the lowest score.

Factor out the task of adding a function name to this mapping.