Adding some backtracking code