WIP

Helper functions to build the backtracking logic.

Embryo of tests.