There is no need to clean up the piddir, and many of the checks were
just slowing the script down-- we minimise these as much as possible.
The test "x$var" != "x" idiom isn't used in rc scripts as our sh does
not have that bug.
I've moved the functions upwards, and decided not to touch the
profiling parts-- they should be in functions, but they work and
are not the only examples of profiles in this way