accidentally removed check if dir already exists logic, adding back + some refactor