Moved pathfinding code to separate file.