Some bugfixes for sqlite