refactored code for hierarchical content