refactor cursor related routines