                     cb()
             # create the 3d renderer
             opts.scene.opts ?= {}
-            opts.scene.opts.cb = init
+            opts.scene.opts.callback = init
 
             obj = new Math3dThreeJS opts.element, opts.scene.opts
     ], (err) ->

        @renderer_type = 'dynamic'

        # remove the current renderer (if it exists)
        remove_element @opts.element.lastChild

        # place renderer in correct place in the DOM
        @opts.element.appendChild @renderer.domElement

        @renderer.setClearColor @opts.background, 1
        @renderer.setSize @opts.width, @opts.height

math3d.threejs_src = "http://cdnjs.cloudflare.com/ajax/libs/three.js/r68/three.min.js"
math3d.orbitcontrols_src = "OrbitControls.js"

remove_element = (element) ->
    if element is null
        return
    if (parent = element.parentElement) is null
        return
    parent.removeChild element

loadScript = (script_src, callback) ->
    run_callback = true

    script = document.createElement 'script'
    script.type = 'text/javascript'
    script.async = true
    script.src = script_src

    script.onload = ->
            remove_element script
            if run_callback
                run_callback = false
                callback()
    script.onerror = ->
            remove_element script
            if run_callback
                run_callback = false
                callback "error loading script #{script.src}"

    document.head.appendChild script

load_threejs = (callback) ->
    if THREE?.Scene? and THREE?.OrbitControls?
        return callback()

    _loading_threejs_callbacks.push callback
    #console.log("load_threejs")
    if _loading_threejs_callbacks.length > 1
        #console.log("load_threejs: already loading...")
        return

    run_callbacks = (error) ->
        for callback in _loading_threejs_callbacks
            callback error
        _loading_threejs_callbacks = []

    loadScript math3d.threejs_src, (error) ->
        if (error)
            run_callbacks error
        else
            loadScript math3d.orbitcontrols_src, run_callbacks
    
math3d.load_threejs = load_threejs

