Backtracking implemented (task 4).