Finished adding comments to all functions and did some other code cleanups.