Better memoization of instances and layers.