Added open cursor check. If cursor is closed it is swapped to  null to be safe.