pathfinding code more beautiful :)