Improvements in ReplaceAll function