Refactor client connection and request