     messageFolded.set id, newDefault
   ## No longer care about this image if it's not referenced and doesn't have
   ## a rendered template.
-  if images[id].count == 0 and id not of id2template
+  if images[id].count == 0 and id not of id2dom
     delete images[id]
     updateFileQuery()
 

  #  Math.floor(Math.random() * 25 + 255 - 25).toString(16) +
  #  Math.floor(Math.random() * 25 + 255 - 25).toString(16)

  ## Scroll to this message if it's been requested.
  if scrollToLater == @data._id
    scrollToLater = null
    scrollToMessage @data._id

  ## Image rotation. Also triggered in formatBody.
  @autorun =>
    data = Template.currentData()  ## update whenever message does

    ## initImage calls updateFileQuery which will do this:
    #images[data._id].file = data.file
    #initImageInternal data.file if data.file?
    ## If message is naturally folded, don't count images it references.
    images[data._id].naturallyFolded = naturallyFolded data
    images[data._id].children = data.children?.length
