Optimized lookups code