Improve the check and fix the issue with PID