Corrected to look for existing records before insert