Implement optimizations for hierarchical bp