 
     console.log("Game code changed to", gameCode)
     sendMessage("loadGameCode", gameCode)
-  $scope.$watch("currentGame", onUpdateCode, true)
+  $scope.$watch("currentGame.version", onUpdateCode, true)
 
   # Call onUpdateGode() if the game history changes 
   onUpdateGameHistory = ->
+    if not currentGame.version? then return
+    if not puppetIsAlive then return
+
     # To check that we haven't updated the game version ourselves
     if gameHistory.meta.version isnt lastGameVersion
-      onUpdateCode()
+      updateFrames()
   $scope.$watch('gameHistoryMeta.version', onUpdateGameHistory, true)
 
   onResize = -> 

            gameHistory.data.compilationErrors = []
            lastGameVersion = ++gameHistory.meta.version

          # 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)

            timing.updateFrames = Date.now()
            # 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 })
      when "recordFrame"
        if message.type is "error" then throw new Error("Cannot deal with recordFrame error message")


  puppetIsAlive = false
  gameCode = null
  oldRoundedScale = null

  # Bring services into the scope
  $scope.currentGame = currentGame
