Fix dependency calculation for flat hierarchy