Improved SQLite code