fixed column order in toMatrixQ function