NCBO-981 fix cycles calculating hierarchy depth