I didn't pretend to make a perfect code but just a functional code, and I share it because it can maybe help people who would encounter the same problem as me.
Don’t feel bad! To get better at something, you must be bad at it first. Consider improvements from feedback in this thread.