In general, it is much better to use pre-implemented modules or libraries that are present and designed for this particular purpose.
This will save you time and allow you to focus on other important tasks.
As a suggestion, you might want to consider using this resource (or see how it works to create your own):