Adding comments to code

Showing areas corrected and adding more explanation.