Converted script to use sqlite3