Matrix refactoring