don't forget to close the cursor
implement query sorting