optimize id replacement