       ledger.api.BlockRestClient.instance.refreshLastBlock()
       @_deleteSynchronizationToken(@_syncToken) if @_syncToken?
       @_syncToken = null
+      duration = moment.duration(new Date().getTime() - startDate.getTime())
+      $info "Stop synchronization. Synchronization took #{duration.get("minutes")}:#{duration.get("seconds")}:#{duration.get("milliseconds")}"
       @stopIfNeccessary()
 
   _performRecovery: (unconfirmedTransactions) ->
     syncToken = null
     savedState = {}
+    persistState = no
     @_loadSynchronizationData().then (data) =>
-      savedState = data
+      savedState = @_migrateSavedState(data)
+      persistState = yes
       @_requestSynchronizationToken()
     .then (token) =>
       @_syncToken = token


  onStart: () ->
    unconfirmedTxs = @_findUnconfirmedTransaction()
    @_performRecovery(unconfirmedTxs).then (transactionsNotFound) =>
      l "Recovery completed"
      @_discardTransactions(transactionsNotFound)

      block.delete()
    @_saveSynchronizationData(savedState)

  _migrateSavedState: (state = {}) ->
    oldBatchSize = state["batch_size"] or 20
    if (oldBatchSize != @BatchSize)
      idx = 0
      while state["account_#{idx}"]?
        oldBatches = state["account_#{idx}"]["batches"]
        batches = []
        total  = oldBatches.length * oldBatchSize
        state["account_#{idx}"] = batches: batches
        idx += 1
    state["batch_size"] = @BatchSize
    state

  @reset: () ->
    @instance = new @
