Matrix/layer refactoring.