Updated to avoid file copying when not necessary.