Improve markDuplicate() logic.