Improve troubleshooting function