generic functions for selecting Layers and writing data + code cleanup in controller