Cursor flags

More changes for #607:

* if a key or value has been copied on entry, it shouldn't be cleared because of a deadlock
* after a NOTFOUND from any operation, but particularly at the end of iteration, cursors should behave as if they are reset
* don't clear the key after a successful remove: it causes problems for loops conditions using compare