refactoring matrix