fix text encoding when calling best_match
add unittest