     self = this
     @el.on 'change', 'td', (evt, newValue) ->
       cell = $(this)
-      rowEl = cell.parent()
-      cells = rowEl.find('td')
-      nameEl = cells.eq(0)
-      name  = nameEl.text().trim()
-      formulaEl = cells.eq(1)
-      formula  = formulaEl.text().trim()
-      self.updateFormula name, formula
+      row = new Row(cell.parent())
+      self.updateFormula row.name(), row.formula()
 
-  updateFormula: (name, formula) -> if name and formula then @loader.setFunctionAsText name, formula
+  updateFormula: (name, formula, oldName) -> if name and formula then @loader.setFunctionAsText name, formula, oldName
 
 
   asText: -> @loader.asText()

    sheetRows = @el.find('tr')
    self = this
    sheetRows.each ->
      rowEl = $(this)
      cells = rowEl.find('td, th')
      nameEl = cells.eq(0)
      name  = nameEl.text().trim()
      formulaEl = cells.eq(1)
      formula  = formulaEl.text().trim()
      self.updateFormula name, formula

  _updateTable: (name, value) ->
    valueCellForName = @el.find('td:first-child').filter( -> $(this).text() == name).closest('tr').find('th:nth-child(3)')
    valueCellForName.text(value)

#module.exports = TableWorksheet
window.TableWorksheet = TableWorksheet
    @loader.loadDefinitions text

  loadRow: (rowIndex, name, formula) ->
    row = new Row(@el.find("tbody tr").eq(rowIndex))
    row.setName name
    row.setFormula formula

  _loadTable: (defs) -> @loadRow(i, def.name, def.expr.text) for def, i in defs

