     framesBeforeGeneration = stepsPerGen
 
     imageNameTemplate = E('upload-name').value
-    
-    @_setCanvasSize()  
-    timerId = setInterval (=>
+    @beginWork()
+    @uploadWorker = setInterval (=>
       observer.navigateTo @startChain, @startOffset
       p = index / totalSteps
       observer.modifyView M.hyperbolicInv Tinterp(p)

  
class Animator
  constructor: ->
    @reset()
    @oldSize = null
    
  reset: ->
    @startChain = null
    @startOffset = null
    @endChain = null
    @endOffset = null
    E('animate-view-start').disabled = true
    E('animate-view-end').disabled = true

  setStart: (observer) ->
    @startChain = observer.getViewCenter()
    @startOffset = observer.getViewOffsetMatrix()
    E('animate-view-start').disabled = false
    
  setEnd: (observer) ->
    @endChain = observer.getViewCenter()
    @endOffset = observer.getViewOffsetMatrix()
    E('animate-view-end').disabled = false
  viewStart: (observer) ->
    observer.navigateTo @startChain, @startOffset
  viewEnd: (observer) ->
    observer.navigateTo @endChain, @endOffset
        
  _setCanvasSize: ->

      index +=1
      framesBeforeGeneration -= 1
      if framesBeforeGeneration is 0
        doStep()
        framesBeforeGeneration = stepsPerGen

      if index > totalSteps
        clearInterval @uploadWorker
        @endWork()
      ), 100

serverSupportsUpload = -> ((""+window.location).match /:8000\//) and true
# ============================================  app code ===============
#
animator = new Animator()
if serverSupportsUpload()
  console.log "Enable upload"
  E('animate-controls').style.display=''

canvas = E "canvas"
context = canvas.getContext "2d"
