refactored Matrix