Fixed sqlite problem with threading.