Minor corrections to search and replace code