Express cosA in terms of t when tan(A/2)=t

i checked the solution but i don't understand it.

solution:

using the half-angle formula for tan, tan^2(A/2)=(1-cosA)/(1+cosA)

therefore cosA=(1-tan^2(A/2))/(1+tan^2(A/2))=(1-t^2)/(1+t^2)

what i don't understand is how they get cosA in terms of tan^2(A/2).

how i would solve it is to multiply both sides of tan^2(A/2)=(1-cosA)/(1+cosA) with (1+cosA), but that won't get me cosA=(1-tan^2(A/2))/(1+tan^2(A/2))