now with support for backtracking.