improved pid handling