Layer switcher code improvements

some smaller changed to simplify the layer switcher code