refactoring: reimplemented error_handling/matrix