make pidfile optional.
fix the nil pointer dereference.