rewriting backtracking