moved creating temporary directory to when it is actually written to