Adjusted logic to take matching criteria over best depth match