Major refactoring of BuildTree.java, which also fixed a bug breaking the
ConstraintFor2InPredicate test.