better handling of mkdir and filenames