optimizations + support for hierarchies