clean up and optimize matching in match_dialogue.lua