Another attempt at correct file locking.