Added comments to code, fixed up some variable references in mainform.