working code after we updated logic for connections