Fixed bugs with multiple layers.