   window.addEventListener("message", windowEventListener) 
   $scope.$on("$destroy", -> window.removeEventListener("message", windowEventListener))
 
+  updateFrames = ->
+    # Don't bother updating if we're playing right now
+    if gameTime.isPlaying then return
+
+    if gameHistory.data.frames.length > 0 and gameHistory.data.frames[0].inputIoData
+      # Notify the user
+      overlay.makeNotification("updating", true)
+
+      # If there are already frames, then update them starting with the current frame
+      inputIoDataFrames = _.pluck(gameHistory.data.frames[gameTime.currentFrameNumber..], "inputIoData")
+
+      # If there are new circuits added, create memory and IO data for them
+      frameMemory = gameHistory.data.frames[gameTime.currentFrameNumber].memory
+      circuitMetas = RW.listCircuitMeta(gameCode.circuits)
+      oldCircuitIds = _.keys(frameMemory)
+      circuitIds = _.pluck(circuitMetas, "id")
+      for newCircuitId in _.difference(circuitIds, oldCircuitIds)
+        frameMemory[newCircuitId] = RW.cloneData(gameCode.circuits[_.findWhere(circuitMetas, { id: newCircuitId }).type].memory)
+        for inputIoDataFrame in inputIoDataFrames
+          inputIoDataFrame[newCircuitId] = inputIoDataFrame.global
+
+      # The memory stored in the current frame
+      sendMessage("updateFrames", { memory: frameMemory, inputIoDataFrames })
+    else
+      # Else just record the first frame
+      initialMemoryData = buildInitialMemoryData(gameCode.circuits)
+      sendMessage("recordFrame", { memory: initialMemoryData })
+
   sendMessage = (operation, value) ->  
     # Note that we're sending the message to "*", rather than some specific origin. 
     # Sandboxed iframes which lack the 'allow-same-origin' header don't have an origin which you can target: you'll have to send to any origin, which might alow some esoteric attacks. 

        overlay.makeNotification("playing")
        sendMessage("startPlaying", { memory: nextMemory })
    else
      timing.stopPlaying = Date.now()
      if gameTime.inRecordMode
        # Notify the user
        overlay.makeNotification("updating", true) # This could take a while...

          hadRecordingErrors = true # Used to notify the user 
          gameTime.isPlaying = false
      when "stopPlaying" 
        $scope.$apply ->
          metError = false

