Added centralized closeLayers method for external calls.