Changed sorting in the function getUnitDag (refer to inner element)