Change connection logic to avoid multiple connections.