Need docstring here and careful attention to <code>tmp_dir</code> possible issue.