Added existence check before replacing