added mutex guard to connected flag