Split scan and replace into two methods