Corrections suggested by jacobvosmaer
Fixed failure to stop and added handling of failure to remove stale pid