Fixed a few bugs for large matrix.