I have a question on a proof in Algebraic Geometry by Robin Hartshorne. Here is the proof:

Theorem. Let Y \subseteq \mathbb{A}^n be an affine variety with affine coordinate ring A(Y). Then \mathcal{O}(Y) \cong A(Y).

Proof. We define a map \alpha : A(Y) \rightarrow \mathcal{O}(Y). Every polynomial f \in A = k[x_1, \ldots, x_n] defines a regular function on \mathbb{A}^n and hence on Y. Thus we have a homomorphism A \rightarrow \mathcal{O}(Y). Its kernel is  I(Y), so we have an injective homomorphism \alpha : A(Y) \rightarrow \mathcal{O}(Y).

Now note that   \mathcal{O}(Y) \subseteq \displaystyle \bigcap_{P \in Y} \mathcal{O}_P, where all our rings are regarded as subrings of K(Y). Now by Theorem 3.2 in Hartshorne parts (b) and (c) we have A(Y) \subseteq          \mathcal{O}(Y)     \subseteq        \displaystyle \bigcap_{m} A(Y)_m  , where  m runs over all maximal ideals of A(Y). Equality now follows from the algebraic fact that if B is an integral domain, then B is equal to the intersection (inside its quotient field) of its localizations at all maximal ideals.

I don't understand this part:

Its kernel is  I(Y), so we have an injective homomorphism \alpha : A(Y) \rightarrow \mathcal{O}(Y).

Why is the kernel  I(Y)? Also, why is this an injective homomorphism? Thanks in advance.