                         input = cell.source
                 set
                     type  : 'cell'
-                    id    : @_new_id()
-                    pos   : pos
+                    id    : existing_ids[n] ? @_new_id()
+                    pos   : n
                     input : input
-                pos += 1
+                n += 1
 
         # Set the kernel and other settings
         kernel = ipynb.metadata?.kernelspec?.name


        @syncdb.exit_undo_mode()

        # delete everything
        @syncdb.delete(undefined, false)



        # Read in the cells
        if ipynb.cells?
            n = 0
            for cell in ipynb.cells
                if cell.source?
                    # "If you intend to work with notebook files directly, you must allow multi-line
