logic for toggling layers