Bug fixes, and added DETACH-CURSOR