fix logic for --replace