Fixed NDF due to the directories variable not grabbing the updated values. Also added error handling for closing the directories.
directories