Cleaning up database cursor usage to help with issue #7