better matching of rest path for backtracking