fixed backtracking bug