Updated code for duplicate entries