implemented the layer collapse functionality