Made backtrack a function.