Properly handle connection lost