fixed overwriting of matrix with deepcopy method