Fix handling of multiple matches

Choose the first match when there are multiple matches