Refactor cursor and iterator.