implement backtrack