Refactor square matrix multiplication solution.