fix bugs when record is duplicated