     # this function acually draws a dataset
 
     redrawDataset: (datasetId) ->
-        datasetElement = @svg.select("g.datasets #dataset-#{datasetId}")
         dataset = @datasets[datasetId]
+        if not dataset
+            return
 
         records = dataset.getRecords()
         paths = dataset.getPaths()

            .attr('fill', 'none')
            .attr('transform', "translate(0,"+ (-@options.height+29)+")")

        
        step = (@scales.y.domain()[1] - @scales.y.domain()[0])/4
        @axis.y.tickValues(
            d3.range(@scales.y.domain()[0],@scales.y.domain()[1]+step, step)

            source: definition.source,
            records: definition.records,
            lineplot: lineplot,
            debounceTime: @options.debounce,
            ordinal: @ordinal,
            element: element
        })

        @reloadDataset(id)

    # remove a dataset. redraws.
