generalizing the patching tree handling