Tweak for SQLite, fix a couple of bugs