improved pid detection