Correct place for setting the layerindex