Replacing check for duplicates