Improve duplicate detection method