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


        @syncdb.exit_undo_mode()

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


                        input = cell.source
                set
                    type  : 'cell'
                    id    : existing_ids[n] ? @_new_id()
                    pos   : n
                    input : input
                n += 1

        # Set the kernel and other settings
        kernel = ipynb.metadata?.kernelspec?.name
