More comments have been added for explanation and clarity.