Factor out depth-first search
Add depth-first search checker that prunes branches