totally rework building of hierarchy