moved pid to function