remove redudant code and change cursor lifecyle management