add error handling for lost connections