refactor from solution pathToGoal