added conditional mkdir checks