filed: Split dir creation

Split dir creation into a different function. Also avoid looping around mkdir.