fix replaceWithLocal logic