Corrected algorithm error in detection and creation of target directory