ENH: move mkdirs to main function