simplify code, handle exceptional case where mkdir fails