refactored directory creation