Fix pid-file logic