Fix a bug in cursors and tweak tests.