Added implementation to unlock the file before closing