properly close cursors