Replace duplicate code with method call.