added handling for lost connection