Improve the check for duplication