'Sort cellvars in the order of varnames and prune from freevars.'

def sort_cellvars(self):

    cells = {}
    for name in self.cellvars:
        cells[name] = 1
    self.cellvars = [name for name in self.varnames if (name in cells)]
    for name in self.cellvars:
        del cells[name]
    self.cellvars = (self.cellvars + cells.keys())
    self.closure = (self.cellvars + self.freevars)
