Updated code to handle conditional value replacemnt.