export longest_match function