Modified to update the palette when toggling between 2D and 3D