                             # just give up -- this isn't at all critical; don't want to waste resources.
                             return
                         @frame = window.frames[@iframe_uuid]
-                        if not @frame? or not @frame.$? or not @frame.IPython.notebook?
+                        if not @frame? or not @frame.$? or not @frame.IPython? or not @frame.IPython.notebook?
                             setTimeout(f, 100)
                         else
                             a = @frame.$("#ipython_notebook").find("a")

                                @_save_checkpoint = @frame.IPython.notebook.save_checkpoint
                                console.log(@_save_checkpoint)
                                @frame.IPython.notebook.save_checkpoint = @save_checkpoint
                    setTimeout(f, 100)

    save_checkpoint: () =>
        console.log("save checkpoint!")
        obj = @to_obj()
        v1 = misc.to_json(obj)
        @doc.live(v1)
        @save_button.icon_spin(true)
        @doc.save () =>
            @save_button.icon_spin(false)
            return
            ###
            console.log("sync'd and got back.")
            v2 = @doc.live()
            if v1 != v2
                console.log("new changes from afar!")
                # here we would somehow merge the two objects obj and obj2
                try
                    @from_obj(misc.from_json(v2))
                catch e
                    console.log("invalid json, so resetting.")
                    @doc.live(v1)
                    @doc.save () =>
                        @doc.save()
            else
                console.log("nothing new")
            ###

    doc_sync: () =>
        console.log("doc sync")
        v1 = @doc.live()
        obj = @to_obj()
        v2 = misc.to_json(obj)
        if v1 != v2
            # TODO -- here *we* would merge the objects defined by v1 and v2, then set live to that and sync it out...
            try
                @from_obj(misc.from_json(v1))
            catch e
                console.log("invalid json, so resetting ", e)
                @from_obj(obj)
                @doc.live(v2)  # definitely good version
                @doc.sync () =>
                    @doc.live(v2)
                    @doc.sync()





    init_buttons: () =>
        @save_button = @element.find("a[href=#save]").click () =>


        @element.find("a[href=#json]").click () =>
            console.log(@to_obj())

    save: () =>
        @frame.IPython.notebook.save_checkpoint()
