fix slow cotmatrix