Better way to check duplicates.
Add comments.