Added cursor.close() to fix resource leak.