Fixes to SQLite db access