Fixed sqlite thread problem