added locking to allow the file to be deleted