Correctly activate and deactivate layers.