Cursor fixes

Fixes several issues related to cursors, including those mentioned in issue #19.

See the commit mesages for details, and let me know if there are any problems or questions.