updated connectToServer method