refactor pathfinding