Added check to temp_dir, create dir if not exist.