Several fixes to the hierarchy generation.