add client terminate detection