fixing of the backtracking algorithm