better threadsafe connecting