Included a few comments in the code to make things more clear