Added check for existing records in database