Depth sorting fixed

Further fixes on depth sorting of root patches and class calcuations.