refactor Matrix multiplication