added code to watch the lifetime of the layer.