Refactoring of classes code for matrix multiplication