Adding comments to help clarify what is taking place within each loop