Optimization of direction lookup