refactored and added hierarchy