adding status flag. removing duplicate code. removing rm for pidfile sin...