Updated algorithm to make it substantial faster for large datasets when partial exact matching is used.