Added code for $replace