         reporter(null)
       when "loadGameCode"
         if loadedGame? then unloadGame()
-        loadGame(message.value)
-        reporter(null)
+        loadGame message.value, (err) ->
+          if err? then return reporter(err, message.operation)
+          reporter(null)
       when "startRecording"
         lastMemory = message.value.memory
         recordedFrames = []

    if splitUrl.mimeType == "text/css" then loadedAssets.data[name].remove()

# The evaluator is initialized with any JS assets.
# Returns object containing two maps: { urls: , data: }
# TODO: move asset handling into gamEvolve.coffee. CSS could be handled by the HTML io. JS is harder.
createAssets = (inputAssets, evaluator) ->
  assetNamesToData = {}

  # Create new assets
  for name, dataUrl of inputAssets

      if splitUrl.mimeType in ["application/javascript", "text/javascript"]
        script = atob(splitUrl.data)
        evaluator(script)
        reportDone(null, name, script)
      else if splitUrl.mimeType == "text/css"
        css = atob(splitUrl.data)
        element = $('<style type="text/css"></style>').html(css).appendTo("head")
        reportDone(null, name, element)
      else if splitUrl.mimeType.indexOf("image/") == 0
        image = new Image()
        image.src = dataUrl
        image.onload = -> reportDone(null, name, image) 
        image.onerror = -> reportDone("Cannot load image '#{name}'")
      else if splitUrl.mimeType.indexOf("audio/") == 0
        arrayBuffer = RW.dataURLToArrayBuffer(dataUrl).buffer
        onSuccess = (buffer) -> reportDone(null, name, buffer)
        onError = (error) -> reportDone("Error decoding audio asset '#{name}'")

        RW.audioContext.decodeAudioData(arrayBuffer, onSuccess, onError)
      else
        reportDone(null, name, atob(splitUrl.data))
  return null

# When complete, calls callback(err)
loadGame = (gameCode, callback) ->
  evaluator = eval
  circuitMetas = RW.listCircuitMeta(gameCode.circuits)
  loadedGame =
    circuits: compileCircuits(gameCode.circuits, evaluator)
    processors: compileProcessors(gameCode.processors, evaluator)
    switches: compileSwitches(gameCode.switches, evaluator)
    transformers: compileTransformers(gameCode.transformers, evaluator)

  createAssets gameCode.assets, evaluator, (err, assetNamesToData) ->
    if err? then return callback(err)

    loadedAssets = assetNamesToData

    # Initialize IO after assets are loaded
    try 
      loadedGame.io = initializeIo(gameCode.circuits)
    catch error
      return callback(error)

    # Keep in play sequence
    if inPlaySequence then enterPlaySequence()

    # Finished
    callback(null)

unloadGame = ->
  destroyAssets()
