Optimize id search