worked on refactoring with tmp_dirs