When removing internal boundaries between faces of the same material do it once for the whole shape, and at this keep boundaries between areas with different material.