Move ensuring existence of directories to latter stages.

in order to prevent creation of uncessary connections to HDFS.