add a cursor test and fix some bugs