Massive refactor to consolidate the way that the hierarchy is maintained.