Added comments in the code to explain what is going on