Fixing two issues when searching for duplictes