Added exception checking for disconnect operations