Updated some comments to clarify what is going on in the code