Fix implementation of deepest_child, and prune dead branches.