tree repair logic.