fixed directory creation logic