Factored out account connection code.