Factored out tree checking code and use it also in TreePotential