moved directory creation out of if