Hello, I have trouble proving that "if f o g is injective, then f is injective."

Let g be a function from X to Y and let f be a function from Y to Z.

My attempt to solving it is by contradiction:

Assume that f is not injective, that is, there exists a z that belongs to Z for each y that belongs to set Y such that f(y) != z.

There exist y1,y2 belong to Y, y1!=y2, such that f(y1)=f(y2).

By definition of injection, y1=g(x1) and y2=g(x2) for some x1, x2 that belong to X,

but x1!=x2 since g(x1)!=g(x2).

Since f(y1)=f(y2), we have f(g(x1))=f(g(x2)), so (fog)(x1)=(fog)(x2), which is a contradiction.

Therefore f is injective

Am I in the correct way?

P.S. I apologize if my symbology is hard to read. I am new to the forum and I am not familiar with the text format.