Added a mutex file lock to allow only one instance at a time

Tried to touch the files as little as possible (except for that trailing space), and tried to adhere to your coding style, kind of.