Moved StreamConnected outside the loop