Changed all self.cursor references to local versions of cursor