Make better use of caching during backtracking