Fixed bugs relating to cursors and ranges