use lockfile package instead of poorly written function taken from random place on stackexchange...
use lockfile, also redo logfiles