Re-arranged the call order of connecting to avoid interrupted connections