Refactored out all the common client creation code.