Complete rewrite to support class trees. Makes the behaviour of the set