Handle the lock file better.

Instead of using "lock file is present" as the check, this should just use flock(), so that manual removal on the event of a crash isn't required.