Here is the code with my comments