Refactoring of linear algebra