added hierarchy calculation