some bugfixes while testing and ensure building sqlite in thread-safe mode