Rewriting signal handler, adding pid file support.