Add gracefully shutdown support