Updated code to fix errors with sqlite3 database