fix some problems with output matrix.