Made pid detection more robust against invalid data (blank, non-numeric)