Add function of dynamically change number of layers.