Functioning backtracking search