Extended algorithm to handle multiple layers of hierarchy
Changed description to state that the algorithm handled mutliple levels of hierarchy