pass scratch_dir via function