# Confusion in computing the $1+|\langle\phi|\psi\rangle|^2$ term in the quantum swap test algorithm

I am having trouble understanding a particular step of the Swap-test algorithm. As I am struggling with this for the past week, I thought I should ask here. So, I get the procedure until right after we measure the probability of the the system to collapse at state $$|0\rangle$$.

$$P(\mathrm{First\:qubit=0})=\frac{1}{2}\big (\langle\phi|\langle\psi|+\langle\psi|\langle\phi|\big)\frac{1}{2}\big (|\phi\rangle|\psi\rangle+|\psi\rangle|\phi\rangle\big)=\frac{1}{2}+\frac{1}{2}|\langle\psi|\phi\rangle|^2$$

In this equation, I cannot understand how we go from the second part to the third part.

If I do the math, I get the second part to be equal with

$$=\frac{1}{4}\big(\langle\phi|\langle\psi||\psi\rangle|\phi\rangle+\langle\psi|\langle\phi||\phi\rangle|\psi\rangle\big)$$

How do we get from that to the third part with the l2-norm?

Perhaps I am missing something really simple here, but I cannot seem to get it.

Remember that when you're multiplying out a term like $$(\langle\phi|\langle\psi|+\langle\psi|\langle\phi|)(|\phi\rangle|\psi\rangle+|\psi\rangle|\phi\rangle)$$ that (i) you get all the corss terms (it's just like multiplying out $$(a+b)(x+y)=ax+ay+bx+by$$, and (ii) order matters in the tensor product (while it remains a tensor product. Once you've taken the inner product and they become just numbers, order doesn't matter any more).
So, you have \begin{align*} (\langle\phi|\langle\psi|+\langle\psi|\langle\phi|)(|\phi\rangle|\psi\rangle+|\psi\rangle|\phi\rangle)&=(\langle\phi|\langle\psi|)(|\phi\rangle|\psi\rangle)+(\langle\phi|\langle\psi|)(|\psi\rangle|\phi\rangle)+(\langle\psi|\langle\phi|)(|\phi\rangle|\psi\rangle)+(\langle\psi|\langle\phi|)(|\psi\rangle|\phi\rangle) \\ &=\langle\phi|\phi\rangle\langle\psi|\psi\rangle+\langle\phi|\psi\rangle\langle\psi|\phi\rangle+\langle\psi|\phi\rangle\langle\phi|\psi\rangle+\langle\psi|\psi\rangle\langle\phi|\phi\rangle \\ &=1+|\langle\phi|\psi\rangle|^2+|\langle\phi|\psi\rangle|^2+1 \end{align*}
You just need to use $$(\langle\phi|\langle\psi|)(|\phi\rangle|\psi\rangle)=1$$ and other similar equation with $$\phi\leftrightarrow\psi$$.