Some minor improvements to locking/unlocking a file.