I am trying to show gauge invarince of the Yang-Mills lagrangian
$$\mathcal{L}= -\frac{1}{4}F_{\mu \nu }^{a}F^{\mu \nu ,a}+\sum_{i,j}^{N}\overline{\psi}_{i} (\delta _{ij}i\partial_{\alpha}\gamma^{\alpha } -\delta _{ij}m+gA_{\alpha }^{a}\gamma^{ \alpha } T^{a}_{ij})\psi_{j},$$ by rewriting it in terms of the covariant derivative $D_{\mu}=\partial_{\mu}-igA^{a}_{\mu}T^{a},$ for which I know that $F_{\mu \nu }=\frac{i}{g}[D_{\mu},D_{\nu}],$ (where $F_{\mu \nu }=F_{\mu \nu }^{a}T^{a}$) and that it transforms as $D_{\mu} \rightarrow U(x)D_{\mu}U^{-1}(x)$ under the gauge transformation. I am stuck with the following two questions:
When evaluating the transformation of the first term, I have seen the idendity $$-\frac{1}{4}F_{\mu \nu }^{a}F^{\mu \nu ,a}=-\frac{1}{2}F_{\mu \nu }^{a}F^{\mu \nu ,b}\text{tr}[T^{a}T^{b}]=-\frac{1}{2} \text{tr} [F_{\mu \nu }F^{\mu \nu}]$$ been used, but I dont understand the second equality. The components of the Yang-Mills field tensor are matrices, so how does one justify including them in the trace? (It is understood that that $T^{a}$ matrices has been normalized so that $\text{tr}[T^{a}T^{b}]=\frac{1}{2}\delta^{ab}$ by the way.)
For the second term of the lagrangian I have seen the equality $$\sum_{i,j}^{N}\overline{\psi}_{i} (\delta _{ij}i \partial_{\alpha}\gamma^{\alpha }-\delta _{ij}m+gA_{\alpha }^{a}\gamma^{ \alpha } T^{a}_{ij})\psi_{j} =\sum_{i,j}^{N}\overline{\psi}_{i} ( i D_{ij, \alpha}\gamma^{\alpha }-\delta _{ij}m)\psi_{j},$$ been used, but I don't understand how this is true unless $gA_{\alpha }^{a}\gamma^{ \alpha } T^{a}_{ij}=0$ for $i\neq j$. I am very eager to know why this equality holds?