Optimized pathfinding.