Better error checking for lock file open and close