added some handling for connectivity problems