Refactored to use pathfind