Updated: make sure to close the cursors