Break out connection and session startup into functions.