Agent shutdown fixes