generic backtracking