Implement some useful functions for layers, to prevent code duplication.