better logic for directory creation