Fix Sqlite tests and minor refactoring

That's weird. TravisCI was showing that build passes, but two tests failed when I run them on my local machine.