Added comment lines to explain what each line of code does