Refactoring + add random matrix generator