This fixes #4955.  It now checks for duplicate records.