updated connection logic