only pass target_dir on if it is specified