Fix pidfile handling