Transfer function and difference equations: why does $H(z)$ numerator polynomial not correspond to $Y(z)$? For a discrete time LTI system, I understand that from a difference equation description of the system in the form 
$$
\sum\limits_{k=0}^N{a_k y[n-k]}=\sum\limits_{k=0}^M{b_k x[n-k]}
$$
I can determine the transfer function of the system in the form 
$$
H(z)=\frac{b_Mz^M+b_{M-1}z^{M-1}+\ldots+b_1z+b_0}{a_Nz^N+a_{N-1}z^{N-1}+\ldots+a_1z+a_0}
$$ 
Given a rationanal transfer function, I can easily go back to the difference equation. However, since the transfer function can also be expressed as $\frac{Y(z)}{X(z)}$,
$$
H(z)=\frac{b_Mz^m+b_{M-1}z^{M-1}+...+b_1z+b_0}{a_Nz^N+a_{N-1}z^{N-1}+...+a_1z+a_0}=\frac{Y(z)}{X(z)}
$$


Doesn't this imply that the polynomial in the numerator corresponds to the output and the denominator corresponds to the input? 


But we know that the numerator polynomial derived from the input side and the denominator derived from the output side of the difference equation.


I'm obviously missing something in my understanding, but I don't see how to resolve this conundrum.  What am I missing?
It is right that $H(z)=\frac{Y(z)}{X(z)}$ and yes, the output is in the numerator. But the numerator of one side is multiplied by the denomarator of the other side to get an equality:

$$H(z)=\frac{b_Mz^M+\cdots+b_0}{a_Nz^N+\cdots+a_0}=\frac{Y(z)}{X(z)}\tag{0}$$
$$\hspace{-1.5cm}\Rightarrow\left(b_Mz^M+b_{M-1}z^{M-1}+\cdots+b_0 \right)X(z)=\left(a_Nz^N+a_{N-1}z^{N-1}+\cdots+a_0\right)Y(z)\tag{1}$$
Taking the inverse $z$ transform from $(1)$ yields the differnce equation of the system:
$$b_Mx[n+M]+b_{M-1}x[n+M-1]+\cdots+b_0=a_Ny[n+N]+\cdots+a_0\tag{2}$$
So indeed, I explained it in the reverse order. Everything begins from the difference equation of a system in $(2)$, then the $z$-transom is applied on it:
$$\hspace{-1cm}b_Mz^MX(z)+b_{M-1}z^{M-1}X(z)+\cdots+b_0 X(z)=a_Nz^NY(z)+a_{N-1}z^{N-1}Y(z)+\cdots+a_0Y(z)\tag{3}$$ and then factoring $X(z)$ on the left and $Y(z)$ on the RHS, we will get to $(1)$. From that, $(0)$ is resulted.

If we [wrongly] had
$$\frac{b_Mz^M+\cdots+b_0}{a_Nz^N+\cdots+a_0}=\frac{X(z)}{Y(z)}\tag{4}$$ then after multiplication we would  get
$$\left(b_Mz^M+b_{M-1}z^{M-1}+\cdots+b_0 \right)Y(z)=\left(a_Nz^N+a_{N-1}z^{N-1}+\cdots+a_0\right)X(z)\tag{5}$$
$$\hspace{-1.5cm}b_Mz^MY(z)+b_{M-1}z^{M-1}Y(z)+\cdots+b_0 Y(z)=a_Nz^NX(z)+a_{N-1}z^{N-1}X(z)+\cdots+a_0X(z)\tag{6}$$
and taking the inverse $z$-transform we would have
 $$\hspace{-2cm}b_My[n+M]+b_{M-1}y[n+M-1]+\cdots+b_0=a_Nx[n+N]+\cdots+a_0\tag{7}$$
which is obviously not the correct difference equation (i.e. $(2)$ that we started from).