fix directory creation mechanism; the optimized version would not work :-(