Ensure cursors are closed