HOPKINS: Fix regression in pathfinding code, some more refactoring