simplify flattenbst