Improved pid writing