Moved client connect/authenticate to helper function