Fixed the logic used to connect to the server.