Build flatten and tree removal