Optimize choose direction logic.