Fixed a bug in way search algorithm.