Fixed directory creation function.