Added extensive comments to code.